const http = require("http");
const url = require("url");
const fs = require("fs");
const server = http.createServer((req, res) => {
  let query = url.parse(req.url, true).query;
  if (typeof query.username !== "undefined") {
    try {
      if (!fs.existsSync("./data.json")) {
        fs.writeFileSync("./data.json");
        JSON.stringify([]);
      }
let arr=JSON.parse(fs.readFileSync('./data.json'))
console.log(arr)
arr.push(query)
console.log(arr)


    } catch (err) {
      console.log(err);
      res.write("error");
    }
  }
  res.end();
});

server.listen(8989);
// let data={
//     name:'张三',
//     age:20
// }
// let bool=fs.existsSync('./data.json')
// console.log(bool)

// if(!bool){
//     fs.writeFileSync('./data.json',JSON.stringify(data))
// }else{
//     console.log('已经写过了')
// }

// const wFile = require("./data.json");
// console.log(wFile.push(1));
